//
//  SISSHouseConditionInfoListCell.m
//  SISSAPP
//
//  Created by 袁应荣 on 2017/9/15.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSHouseConditionInfoListCell.h"
#import "SISSHouseConditionInfoModel.h"
#import "SISSContractModel.h"

@interface SISSHouseConditionInfoListCell ()

/// 日期Label
@property (weak, nonatomic) UILabel *timeVersionLabel;
/// 信息来源Label
@property (weak, nonatomic) UILabel *infoSourceLabel;

/// 中介人员姓名Label
@property (weak, nonatomic) UILabel *brokerNameLabel;
/// 看房记录标签Label
@property (weak, nonatomic) UILabel *tagLabel;
/// 底部线条
@property (weak, nonatomic) UIView *lineView;

@end
@implementation SISSHouseConditionInfoListCell

- (void)setHouseConditionInfoModel:(SISSHouseConditionInfoModel *)houseConditionInfoModel {
    _houseConditionInfoModel = houseConditionInfoModel;
    
    self.timeVersionLabel.text = [NSString stringWithFormat:@"%@版",[houseConditionInfoModel.insertTime substringToIndex:10]];
    self.brokerNameLabel.text = houseConditionInfoModel.name;
    if (houseConditionInfoModel.latestVersion == 1) {
        self.tagLabel.textColor = SECONDARY_TEXT_COLOR;
        self.tagLabel.text = @"当前最新版本";
        self.tagLabel.hidden = NO;
    } else {
        self.tagLabel.hidden = YES;
    }
//    if (houseConditionInfoModel.isValid == 0) { //已失效
//        self.tagLabel.textColor = SECONDARY_TEXT_COLOR;
//        self.tagLabel.text = @"已失效";
//        self.tagLabel.hidden = NO;
//    } else if (houseConditionInfoModel.latestVersion == 1) {
//        self.tagLabel.textColor = SECONDARY_TEXT_COLOR;
//        self.tagLabel.text = @"当前最新版本";
//        self.tagLabel.hidden = NO;
//    } else if (houseConditionInfoModel.sellerState == 0) {
//        self.tagLabel.textColor = COLOR(0xFF1F1D);
//        self.tagLabel.text = @"等待签署";
//        self.tagLabel.hidden = NO;
//    } else {
//        self.tagLabel.hidden = YES;
//    }
}

- (void)setContractModel:(SISSContractModel *)contractModel {
    _contractModel = contractModel;
    
    self.timeVersionLabel.text = contractModel.leftStr;
    self.brokerNameLabel.text = contractModel.rightStr;
    self.tagLabel.text = @" 最新版 ";
    self.tagLabel.textAlignment = NSTextAlignmentCenter;
    self.tagLabel.layer.borderWidth = 1;
    self.tagLabel.layer.cornerRadius = 2;
    
    
    WeakSelf
    CGFloat margin = 8.0;
    [self.tagLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.timeVersionLabel);
        make.left.equalTo(weakSelf.timeVersionLabel.mas_right).offset(2 * margin);
        make.size.mas_equalTo(CGSizeMake(8 * margin, 3 * margin));
    }];
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    UILabel *timeVersionLabel = [[UILabel alloc] init];
    timeVersionLabel.textColor = MAIN_TEXT_COLOR;
    timeVersionLabel.font = [UIFont systemFontOfSize:13];
    timeVersionLabel.text = @"2017-10-10版";
    [self.contentView addSubview:timeVersionLabel];
    self.timeVersionLabel = timeVersionLabel;
    
    UILabel *infoSourceLabel = [[UILabel alloc] init];
    infoSourceLabel.textColor = MAIN_TEXT_COLOR;
    infoSourceLabel.font = [UIFont systemFontOfSize:13];
    infoSourceLabel.text = @"信息来源：";
    [self.contentView addSubview:infoSourceLabel];
    self.infoSourceLabel = infoSourceLabel;

    
    UILabel *brokerNameLabel = [[UILabel alloc] init];
    brokerNameLabel.textColor = MAIN_TEXT_COLOR;
    brokerNameLabel.font = [UIFont systemFontOfSize:13];
    brokerNameLabel.text = @"中介人员";
    [self.contentView addSubview:brokerNameLabel];
    self.brokerNameLabel = brokerNameLabel;
    
    UILabel *tagLabel = [[UILabel alloc] init];
    tagLabel.textColor = SECONDARY_TEXT_COLOR;
    tagLabel.font = [UIFont boldSystemFontOfSize:13];
    tagLabel.text = @"当前最新版本";
    [self.contentView addSubview:tagLabel];
    self.tagLabel = tagLabel;
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    self.lineView = lineView;
}


#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    WeakSelf
    [self.timeVersionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(weakSelf.contentView).offset(2 * margin);
    }];
    
    [self.infoSourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.timeVersionLabel);
        make.top.equalTo(weakSelf.timeVersionLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.brokerNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.infoSourceLabel.mas_right);
        make.centerY.equalTo(weakSelf.infoSourceLabel);
    }];
    
    [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.contentView);
        make.right.equalTo(weakSelf.contentView).offset(-2 * margin);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.infoSourceLabel.mas_bottom).offset(2 * margin);
        make.left.right.bottom.equalTo(weakSelf.contentView);
        make.height.mas_equalTo(1);
    }];
}

@end
